< previous page page_185 next page >

Page 185
Inserting Debug Identifiers for VB Classes
You can use Class Builder or Visual Modeler to insert debugging identifiers in your Visual Basic classes. This is extremely helpful for debugging runtime errors. Listing 8.3, in fact, includes debugging identifiers and debugging code.
As long as you're in debug mode, all of the debugging code inserted by Class Builder, Visual Modeler, or yourself is active. You activate debug mode by entering the following code in the General Declarations section of the desired class:
'set this to 0 to disable debug code in this class
#Const DebugMode = 1
You deactivate debug mode as follows:
#Const DebugMode = 0
If DebugMode = 1, any code in the following code body is active:
#If DebugMode Then
    'Your debug mode code here

#End If
If DebugMode = 1, such code is not active, meaning that the code won't show up in your project executable or ActiveX component.
Every class that you want to be tracked for debugging will have a private property, mlClassDebugID, associated with the public property ClassDebugID. This identifier, a purely runtime creature, is assigned a value in the class's Initialize event and is used to help identify the class for global debugging. In General Declarations of the class, the following code is inserted by Class Builder or Visual Modeler:
#If DebugMode Then
    'local variable to hold the serialized class ID that
    'was created in Class_Initialize
    ##ModelId=349AE9A00316
    Private mlClassDebugID As Long
#End If

#If DebugMode Then
    '##ModelId=349AE9A30398
    Public Property Get ClassDebugID()
        'if you are in debug mode, surface this property that consumers can query
        ClassDebugID = mlClassDebugID
    End Property
#End If

 
< previous page page_185 next page >

If you like this book, buy it!